package com.afc.struts.test.persons;

import java.util.List;
import java.util.Vector;

import com.afc.struts.form.ActionForm;
import com.afc.struts.test.data.PersonDao;
import com.afc.struts.test.model.Person;
import com.afc.struts.utils.LabeledBoolean;

public interface PersonsForm extends ActionForm
{
  public List<Person> getPersons();

  public int getSelectedPersonId();
  public void setSelectedPersonId(int aSelectedPersonId);

  public class DefaultPersonsForm implements PersonsForm
  {
    @Override
    public List<Person> getPersons()
    {
      return persons;
    }

    @Override
    public int getSelectedPersonId()
    {
      return selectedPersonId;
    }

    @Override
    public void setSelectedPersonId(int aSelectedPersonId)
    {
      selectedPersonId = aSelectedPersonId;
    }

    @Override
    public LabeledBoolean validateForm()
    {
      return LabeledBoolean.OK;
    }

    protected List<Person> persons = new Vector<>(PersonDao.getInstance().retrieveAll());
    protected int selectedPersonId;
  }
}
